import 'package:flutter/material.dart';
import 'package:flutter_demo/ui/pages/status/inherited/notifier/inherited_notifier_test_widget.dart';
import 'package:flutter_demo/ui/pages/status/inherited/trans/inherited_trans_test_widget.dart';
import 'package:flutter_demo/ui/pages/status/inherited/update/inherited_update_test_widget.dart';
import 'package:flutter_demo/ui/pages/status/widget/dark_extendable_navigation.dart';

var tabTitle = ["trans", "update", "notifier"];

class InheritedTestWidget extends StatefulWidget {
  const InheritedTestWidget({Key? key}) : super(key: key);

  @override
  State<InheritedTestWidget> createState() => _InheritedTestState();
}

class _InheritedTestState extends State<InheritedTestWidget> {
  final PageController _controller = PageController();

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        DarkExtendableNavigation(
          onDestinationSelected: _onDestinationSelected,
          navigationRailDestination: buildNavigationRailDestination(),
        ),
        //占满剩余空间
        Expanded(child: buildView())
      ],
    );
  }

  void _onDestinationSelected(int value) {
    _controller.jumpToPage(value);
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  Widget buildView() {
    return PageView(
        controller: _controller,
        children: tabTitle.map((e) {
          if (e == "trans") {
            return InheritedTransTestWidget();
          } else if (e == "update") {
            return InheritedUpdateTestWidget();
          } else if (e == "notifier") {
            return InheritedNotifierTestWidget();
          } else {
            return Container();
          }
        }).toList());
  }

  List<NavigationRailDestination> buildNavigationRailDestination() {
    return tabTitle.map((e) {
      return NavigationRailDestination(
          icon: Icon(Icons.device_unknown), label: Text(e));
    }).toList();
  }
}
